# -*- encoding: utf-8 -*-
__metaclass__ = type
from visual import *
import ObjectShapes as obs

# Type definition
pos = vector  # to convenient some pos calculation


# Data


# Classes
class Car:
    def __init__(self, road, lane, model="car"):
        road.add_a_car(self)
        self.__pos = None
        self.__v = None
        self.__a = None
        self.__w = None  # omega, angular velocity

    def get_pos(self):
        return self.__pos

    def make_shape(self, model):
        if model == "car":pass
        elif model == "bus":pass

    def rule_keep_distance(self):pass
    def rule_keep_velocity(self):pass

    def drive(self):
        self.rule_keep_distance()
        "..."


class CrossRoad(frame, obs):
    __cars = []

    def __init__(self, frame):
        self.LightState = None  # define later
        self.f = frame
        # the bricks used to border the road, "fl" means front left, and "fm" means front medium, etc.
        self.bricks = \
            {"fl":None, "fm":None, "fr":None,
             "bl":None, "bm":None, "br":None,
             "lf":None, "lm":None, "lb":None,
             "rf":None, "rm":None, "rb":None
             }
        self.color = (0,1,0)
        self.width = 3.5  # width of the road of one direction, Chinese Standard is 3.75m, 4 lanes
        self.brickLength    = 20    # length of the road we show
        self.brickThickness = 0.5   # thickness of bricks
        self.brickHeight    = 1

        self.make_shape(self.f)

    def add_a_car(self, car):
        self.__cars.append(car)




# Functions
def half(x):
    return x / 2.0


# Initialization
scene = display(title=u"十字路口模拟器".encode("gbk"))
scene.fov = pi/8
scene.forward = (0, -1, -1)
crd_f = frame()
crd = CrossRoad(crd_f)


# Main Loop
while 1:
    rate(1)
    #print "scene: ",scene.up,scene.forward
    #print "frame: ",
    #print crd_f.up